#include <iostream>
using namespace std;

const int N = 1e6 + 10;

int n, q;
int arr[N];
int brr[N];
int tmps[N];

void copy()
{
	for (int i = 1; i <= n; i++)
	{
		tmps[i] = arr[i];
	}
}

int main()
{
	cin >> n >> q;

	for (int i = 1; i <= n; i++)
		cin >> arr[i];

	for (int i = 1; i <= q; i++)
		cin >> brr[i];

	for (int i = 1; i <= q; i++)
	{
		if (brr[i] == 1)
		{
			int tmp = arr[1]; // 第一个元素
			for (int i = 1; i <= n - 1; i++)
				tmps[i] = arr[i + 1];
			tmps[n] = tmp;

			copy();
		}
		else
		{
			int tmp = arr[n]; // 最后一个元素
			for (int i = n; i >= 2; i--)
				tmps[i] = arr[i - 1];
			tmps[1] = tmp;
			copy();
		}
	}

	for (int i = 1; i <= n; i++)
		cout << tmps[i] << " ";
	cout << endl;

	return 0;
}